package com.hhc.controller;

import com.hhc.dto.SystemConfigDTO;
import com.hhc.query.SystemConfigQuery;
import com.hhc.service.SystemConfigService;
import com.hhc.utils.RestResult;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *   系统配置管理控制器
 * </p>
 * @author pc
 */
@Slf4j
@RestController
@RequestMapping("/system-config")
public class SystemConfigController {

    @Autowired
    private SystemConfigService systemConfigService;

    @PostMapping("/add")
    public RestResult addSystemConfig(@RequestBody @Valid SystemConfigDTO systemConfigDTO) {
        return systemConfigService.addSystemConfig(systemConfigDTO);
    }

    @PostMapping("/update")
    public RestResult updateSystemConfig(@RequestBody @Valid SystemConfigDTO systemConfigDTO) {
        return systemConfigService.updateSystemConfig(systemConfigDTO);
    }

    @PostMapping("/delete")
    public RestResult deleteSystemConfig(@RequestParam Long configId) {
        return systemConfigService.deleteSystemConfig(configId);
    }

    @GetMapping("/list")
    public RestResult getSystemConfigList(@RequestParam(required = false) String configKey) {
        SystemConfigQuery systemConfigQuery = new SystemConfigQuery();
        systemConfigQuery.setConfigKey(configKey);
        return systemConfigService.getSystemConfigList(systemConfigQuery);
    }

    @GetMapping("/get")
    public RestResult getSystemConfigByKey(@RequestParam @NotBlank(message = "配置键名不能为空") String configKey) {
        return systemConfigService.getSystemConfigByKey(configKey);
    }
}